/**
 * Simple 8 pixel bitmap font for vertical LED bars
 * 
 * @author sven.tiffe@googlemail.com
 */
public class BitmapFont8px {

    /**
     * Return an array of bytes that represents the vertical bits of a
     * character. This fonts supports the ASCII character range from 32 to 127.
     * 
     * @param c
     *            - a character
     * @return a byte array representing the character or a byte array
     *         representing an unknown character
     */
    public static byte[] getCharacterAsBitmap(char c) {
        if (c >= 33 && c <= 127) {
            return font8_33_127[c - 33];
        } else if (c == 32) {
            return space;
        } else {
            return unknown;
        }
    }

    // four pixel wide space
    static private byte space[] = { 0, 0, 0, 0 };

    // unknown
    static private byte unknown[] = { (byte) 0xff, (byte) 0x81, (byte) 0x81,
            (byte) 0x81, (byte) 0xff };

    static public byte font8_33_127[][] = { { 0x5f }, // !
            { 0x04, 0x03, 0x04, 0x03 }, // "
            { 0x14, 0x7f, 0x14, 0x7f, 0x14 }, // #
            { 0x24, 0x2a, 0x6b, 0x2a, 0x12 }, // $
            { 0x43, 0x30, 0x08, 0x06, 0x61 }, // %
            { 0x30, 0x4a, 0x5d, 0x32, 0x48 }, // &
            { 0x04, 0x03 }, // '
            { 0x1c, 0x22, 0x41, 0x41 }, // (
            { 0x41, 0x41, 0x22, 0x1c }, // )
            { 0x14, 0x08, 0x08, 0x14 }, // *
            { 0x08, 0x08, 0x3e, 0x08, 0x08 }, // +
            { (byte) 0xe0 }, // ,
            { 0x08, 0x08, 0x08, 0x08, 0x08 }, // -
            { 0x60 }, // .
            { 0x40, 0x30, 0x08, 0x06, 0x01 }, // /
            { 0x3e, 0x51, 0x49, 0x45, 0x3e }, // 0
            { 0x40, 0x42, 0x7f, 0x40, 0x40 }, // 1
            { 0x62, 0x51, 0x49, 0x49, 0x66 }, // 2
            { 0x22, 0x41, 0x49, 0x49, 0x36 }, // 3
            { 0x18, 0x14, 0x12, 0x11, 0x7f }, // 4
            { 0x27, 0x45, 0x45, 0x45, 0x39 }, // 5
            { 0x3c, 0x4a, 0x49, 0x49, 0x30 }, // 6
            { 0x03, 0x01, 0x71, 0x09, 0x07 }, // 7
            { 0x36, 0x49, 0x49, 0x49, 0x36 }, // 8
            { 0x06, 0x49, 0x49, 0x29, 0x1e }, // 9
            { 0x66 }, // :
            { (byte) 0xe6 }, // ;
            { 0x08, 0x14, 0x22, 0x41 }, // <
            { 0x24, 0x24, 0x24, 0x24, 0x24 }, // =
            { 0x41, 0x22, 0x14, 0x08 }, // >
            { 0x02, 0x01, 0x51, 0x09, 0x06 }, // ?
            { 0x3e, 0x41, 0x5d, 0x5d, 0x51, 0x1e }, // @
            { 0x7e, 0x09, 0x09, 0x09, 0x7e }, // A
            { 0x7f, 0x45, 0x45, 0x45, 0x3a }, // B
            { 0x3e, 0x41, 0x41, 0x41, 0x22 }, // C
            { 0x7f, 0x41, 0x41, 0x41, 0x3e }, // D
            { 0x7f, 0x45, 0x45, 0x41, 0x41 }, // E
            { 0x7f, 0x05, 0x05, 0x01, 0x01 }, // F
            { 0x3e, 0x41, 0x45, 0x45, 0x3d }, // G
            { 0x7f, 0x04, 0x04, 0x04, 0x7f }, // H
            { 0x41, 0x7f, 0x41 }, // I
            { 0x20, 0x40, 0x40, 0x40, 0x3f }, // J
            { 0x7f, 0x04, 0x04, 0x0a, 0x71 }, // K
            { 0x7f, 0x40, 0x40, 0x40, 0x40 }, // L
            { 0x7f, 0x02, 0x04, 0x02, 0x7f }, // M
            { 0x7f, 0x02, 0x04, 0x08, 0x7f }, // N
            { 0x3e, 0x41, 0x41, 0x41, 0x3e }, // O
            { 0x7f, 0x05, 0x05, 0x05, 0x02 }, // P
            { 0x3e, 0x41, 0x41, 0x21, 0x5e }, // Q
            { 0x7f, 0x05, 0x05, 0x05, 0x7a }, // R
            { 0x22, 0x45, 0x45, 0x45, 0x39 }, // S
            { 0x01, 0x01, 0x7f, 0x01, 0x01 }, // T
            { 0x3f, 0x40, 0x40, 0x40, 0x3f }, // U
            { 0x0f, 0x30, 0x40, 0x30, 0x0f }, // V
            { 0x7f, 0x20, 0x10, 0x20, 0x7f }, // W
            { 0x71, 0x0a, 0x04, 0x0a, 0x71 }, // X
            { 0x01, 0x02, 0x7c, 0x02, 0x01 }, // Y
            { 0x61, 0x51, 0x49, 0x45, 0x43 }, // Z
            { 0x7f, 0x41, 0x41 }, // [
            { 0x01, 0x06, 0x08, 0x30, 0x40 }, // \
            { 0x41, 0x41, 0x7f }, // ]
            { 0x04, 0x02, 0x01, 0x02, 0x04 }, // ^
            { 0x40, 0x40, 0x40, 0x40, 0x40 }, // _
            { 0x03, 0x04 }, // `
            { 0x20, 0x54, 0x54, 0x54, 0x78 }, // a
            { 0x7f, 0x48, 0x44, 0x44, 0x38 }, // b
            { 0x38, 0x44, 0x44, 0x44, 0x28 }, // c
            { 0x38, 0x44, 0x44, 0x48, 0x7f }, // d
            { 0x38, 0x54, 0x54, 0x54, 0x58 }, // e
            { 0x04, 0x7e, 0x05, 0x05 }, // f
            { (byte) 0x98, (byte) 0xa4, (byte) 0xa4, (byte) 0xa4, 0x7c }, // g
            { 0x7f, 0x08, 0x04, 0x04, 0x78 }, // h
            { 0x7d }, // i
            { 0x60, (byte) 0x80, (byte) 0x80, (byte) 0x80, 0x7d }, // j
            { 0x7f, 0x10, 0x28, 0x44 }, // k
            { 0x3f, 0x40 }, // l
            { 0x7c, 0x04, 0x18, 0x04, 0x78 }, // m
            { 0x7c, 0x04, 0x04, 0x04, 0x78 }, // n
            { 0x38, 0x44, 0x44, 0x44, 0x38 }, // o
            { (byte) 0xfc, 0x28, 0x24, 0x24, 0x18 }, // p
            { 0x18, 0x24, 0x24, 0x28, (byte) 0xfc }, // q
            { 0x7c, 0x08, 0x04, 0x04, 0x08 }, // r
            { 0x48, 0x54, 0x54, 0x54, 0x24 }, // s
            { 0x04, 0x3f, 0x44 }, // t
            { 0x3c, 0x40, 0x40, 0x40, 0x7c }, // u
            { 0x1c, 0x20, 0x40, 0x20, 0x1c }, // v
            { 0x3c, 0x40, 0x70, 0x40, 0x7c }, // w
            { 0x44, 0x28, 0x10, 0x28, 0x44 }, // x
            { (byte) 0x9c, (byte) 0xa0, (byte) 0xa0, (byte) 0xa0, 0x7c }, // y
            { 0x44, 0x64, 0x54, 0x4c, 0x44 }, // z
            { 0x08, 0x36, 0x41, 0x41 }, // {
            { 0x77 }, // |
            { 0x41, 0x41, 0x36, 0x08 }, // }
            { 0x02, 0x01, 0x01, 0x02, 0x02, 0x01 } // ~
    };
}

